// pages/consultant/consultant.js
var app = getApp()
const $api = require('../../utils/api.js').API;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 组件所需的参数
    navbarData: {
      havebg: 1, //1表示显示    0表示不显示
      out: 1, //是否显示左上角图标   1表示显示    0表示不显示
      title: '商品列表', //导航栏 中间的标题
      bg: '#fff', //导航背景
    },
    height: app.globalData.height,
    status: 'qb',//qb全部' ' 其他状态正常
    page: 1,
    gwdata: {},
    gwlist: [],
    showPicker: false,
    selectedPeriod: null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let _this = this
   
  },
  onShow(){
    let _this = this
    _this.ongwData()
  },
  out(){
    wx.navigateBack({
      delta: 1,
    })
  },
  onStatus(e) {
    this.setData({
      page: 1,
      status: e.currentTarget.dataset.status
    })
    this.ongwData()
  },
  ongwData() {
    let _this = this
    $api.getgwzdapplylists({
      login_token: wx.getStorageSync('login_token'),
      per_page: 10,
      page: _this.data.page,
      status: _this.data.status == 'qb' ? '' : _this.data.status
    }).then((res) => {
      if (res.data.code == 0) {
        let gwlist = _this.data.gwlist
        if (res.data.data.data.length <= 0) {
          _this.setData({
            onLoadMore: false
          })
          wx.showToast({
            title: _this.data.page == 1 ? '暂无数据' : '到底了',
            icon: 'none',
            duration: 2000
          })
          if(_this.data.page == 1){
            _this.setData({ gwlist: []  })
          }
          _this.setData({ nofive: true, })
        } else {
          if(_this.data.page == 1){
            gwlist = res.data.data.data
          }else{
            gwlist = gwlist.concat(res.data.data.data)
            
          }
          _this.setData({
            gwlist,
          })
        }
        console.log(res.data.data)
        _this.setData({
          gwdata: res.data.data,
          gwzd_num: res.data.gwzd_num,
          // loadModal: false,
        })
      }

    }).catch((err) => {
      _this.setData({
        // loadModal: false
      })
    })
  },

  goapply() {
    let gwzd_num = this.data.gwzd_num
    if(!gwzd_num){
      wx.showToast({
        title: '暂无申请驻店次数',
        icon: 'none',
        duration: 2000
      })
      return
    }
    wx.navigateTo({
      url: '/pages/consultantapply/consultantapply',
    })
  },
  onReachBottom() {
    let _this = this
    let page = _this.data.page
    if (_this.data.nofive) {
      return
    }
    page++
    _this.setData({
      page
    })
    _this.ongwData()
  },
  scroll: function (e) {
    // console.log(e)
    this.setData({
      scrollTop: e.detail.scrollTop
    });
    if (e.detail.scrollTop >= 50) {
      this.setData({
        headerBg: true
      })
    } else {
      this.setData({
        headerBg: false
      })
    }
  },
  goeval(e){
    console.log(e)
    wx.navigateTo({
      url: '/pages/consultanteval/consultanteval?id=' + e.currentTarget.dataset.id,
    })
    
  }
})